package enterprise.web.tookit.account;

import java.io.Serializable;
import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.PostLoad;
import javax.persistence.PostPersist;
import javax.persistence.PostRemove;
import javax.persistence.PostUpdate;
import javax.persistence.PrePersist;
import javax.persistence.PreRemove;
import javax.persistence.PreUpdate;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.log4j.Logger;

import enterprise.web.tookit.util.FormatDateUtil;

/**
 * 
 * @author regisrocha
 * 
 * @since 28/08/2012
 * 
 * @description Classe representante da entidade enterprisewebtoolkit_db.Account
 * 
 */
@Entity(name = "Account")
public class Account implements Serializable {

	/**
	 * Serial version
	 */
	private static final long serialVersionUID = -2823116823775968761L;

	/**
	 * LOG
	 */
	private final static Logger log = Logger.getLogger(Account.class);

	private Integer id;
	private String email;
	private String gender;
	private String lastname;
	private String password;
	private String username;
	private String firstname;
	private String mobilephone;
	private Calendar birthday = new GregorianCalendar();

	/**
	 * @return the id
	 */
	@Id
	@GeneratedValue
	@Column(name = "id", nullable = false)
	public Integer getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @return the email
	 */
	@Column(name = "email", length = 200, nullable = false)
	public String getEmail() {
		return email;
	}

	/**
	 * @param email
	 *            the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return the gender
	 */
	@Column(name = "gender", length = 1)
	public String getGender() {
		return gender;
	}

	/**
	 * @param gender
	 *            the gender to set
	 */
	public void setGender(String gender) {
		this.gender = gender;
	}

	/**
	 * @return the lastname
	 */
	@Column(name = "lastname", length = 255)
	public String getLastname() {
		return lastname;
	}

	/**
	 * @param lastname
	 *            the lastname to set
	 */
	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	/**
	 * @return the password
	 */
	@Column(name = "password", length = 45)
	public String getPassword() {
		return password;
	}

	/**
	 * @param password
	 *            the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * @return the username
	 */
	@Column(name = "username", length = 45, updatable = false)
	public String getUsername() {
		return username;
	}

	/**
	 * @param username
	 *            the username to set
	 */
	public void setUsername(String username) {
		this.username = username;
	}

	/**
	 * @return the firstname
	 */
	@Column(name = "firstname", length = 100)
	public String getFirstname() {
		return firstname;
	}

	/**
	 * @param firstname
	 *            the firstname to set
	 */
	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	/**
	 * @return the mobilephone
	 */
	@Column(name = "mobilephone", length = 50)
	public String getMobilephone() {
		return mobilephone;
	}

	/**
	 * @param mobilephone
	 *            the mobilephone to set
	 */
	public void setMobilephone(String mobilephone) {
		this.mobilephone = mobilephone;
	}

	/**
	 * @return the birthday
	 */
	@Column(name = "birthday")
	@Temporal(TemporalType.DATE)
	public Calendar getBirthday() {
		return birthday;
	}

	/**
	 * @param birthday
	 *            the birthday to set
	 */
	public void setBirthday(Calendar birthday) {
		this.birthday = birthday;
	}

	@Override
	public String toString() {
		final StringBuilder toString = new StringBuilder();

		toString.append(" ID: " + this.id);
		toString.append(" EMAIL: " + this.email);
		toString.append(" GENDER: " + this.gender);
		toString.append(" LASTNAME: " + this.lastname);
		toString.append(" USERNAME: " + this.username);
		toString.append(" FIRSTNAME: " + this.firstname);
		toString.append(" MOBILEPHONE: " + this.mobilephone);

		final String dt = FormatDateUtil.formataDataPtBR(this.birthday);
		if (dt != null) {
			toString.append(" BIRTHDAY: " + dt);
		} else {
			toString.append(" BIRTHDAY is null");
		}

		return toString.toString();
	}

	@PostLoad
	public void postLoad() {
		log.info("Loading account: " + this.toString());
	}

	@PrePersist
	public void prePersistAccount() {
		log.info("Persisting account: " + this.toString());
	}

	@PostPersist
	public void postPersistAccount() {
		log.info("Account persisted, ID: " + this.id);
	}

	@PreUpdate
	public void preUpdateAccount() {
		log.info("Pre updating account: " + this.toString());
	}

	@PostUpdate
	public void postUpdateAccount() {
		log.info("Account updated, iD: " + this.id);
	}

	@PreRemove
	public void preRemoveAccount() {
		log.info("Pre removing account: " + this.toString());
	}

	@PostRemove
	public void postRemoveAccount() {
		log.info("Account Removed, name: " + this.firstname);
	}

}
